package dp.back01;

import java.util.Arrays;

//1049. 最后一块石头的重量 II
public class Num1049_lastStoneWeightII {
    public int lastStoneWeightII(int[] stones) {
        int[]dp = new int[15001];
        int sum = Arrays.stream(stones).sum();
        int target = sum / 2;
        for (int i = 0; i < stones.length; i++) {
            for (int j = target; j >= stones[i] ; j--) {
                dp[j] = Math.max(dp[j] , dp[j - stones[i]] + stones[i]);
            }
        }
        return sum - dp[target] - dp[target];

    }
}
